package cn.yhjz.generator.service.impl;

import cn.yhjz.common.Pager;
import cn.yhjz.generator.entity.SysGenTemplate;
import cn.yhjz.generator.service.ISysGenTemplateService;
import cn.yhjz.generator.vo.SysGenTemplateVo;
import cn.yhjz.generator.mapper.SysGenTemplateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = {Exception.class})
public class SysGenTemplateServiceImpl implements ISysGenTemplateService {

    @Autowired
    private SysGenTemplateMapper sysGenTemplateMapper;


    @Override
    public Pager getPage(Long currentPage, Long pageSize, SysGenTemplate sysGenTemplate) {
        Pager pager = new Pager();
        Long count = sysGenTemplateMapper.getPageCount(sysGenTemplate);
        Long pageOffset = (currentPage - 1) * pageSize;
        List<SysGenTemplateVo> records = sysGenTemplateMapper.getPage(pageOffset, pageSize, sysGenTemplate);
        pager.setRows(records);
        pager.setCurrentPage(currentPage);
        pager.setPageSize(pageSize);
        pager.setTotalPageCount(count);
        return pager;
    }

    @Override
    public SysGenTemplate insert(SysGenTemplate sysGenTemplate) {
        int res = sysGenTemplateMapper.insert(sysGenTemplate);
        if(res > 0){
            return sysGenTemplate;
        }else{
            return null;
        }
    }

    @Override
    public List<SysGenTemplate> select(SysGenTemplate sysGenTemplate) {
        return sysGenTemplateMapper.select(sysGenTemplate);
    }

    @Override
    public List<SysGenTemplateVo> selectVo(SysGenTemplate sysGenTemplate) {
        return sysGenTemplateMapper.selectVo(sysGenTemplate);
    }

    @Override
    public SysGenTemplate selectOne(SysGenTemplate sysGenTemplate) {
        return sysGenTemplateMapper.selectOne(sysGenTemplate);
    }

    @Override
    public SysGenTemplateVo selectOneVo(SysGenTemplate sysGenTemplate) {
        return sysGenTemplateMapper.selectOneVo(sysGenTemplate);
    }

    @Override
    public SysGenTemplateVo selectById(Long id) {
        return sysGenTemplateMapper.selectById(id);
    }

    @Override
    public int deleteById(Long id) {
        return sysGenTemplateMapper.deleteById(id);
    }

    @Override
    public int updateByIdWithNull(SysGenTemplate sysGenTemplate) {
        return sysGenTemplateMapper.updateByIdWithNull(sysGenTemplate);
    }

    @Override
    public int updateById(SysGenTemplate sysGenTemplate) {
        return sysGenTemplateMapper.updateById(sysGenTemplate);
    }

    @Override
    public int update(SysGenTemplate entity, SysGenTemplate param) {
        return sysGenTemplateMapper.update(entity, param);
    }

    @Override
    public int updateWithNull(SysGenTemplate entity, SysGenTemplate param) {
        return sysGenTemplateMapper.updateWithNull(entity, param);
    }
}
